home *** CD-ROM | disk | FTP | other *** search
/ The CICA Windows Explosion! / The CICA Windows Explosion! - Disc 2.iso / winsock / serweb03.zip / SERWEVW.H < prev    next >
C/C++ Source or Header  |  1993-10-12  |  4KB  |  118 lines

  1. // serwevw.h : interface of the CSerwebView class
  2. //
  3. /////////////////////////////////////////////////////////////////////////////
  4. #define COLUMN_MAX 80        // How many columns to allow for the screen
  5.  
  6. // WWW variables below..  We will read from a file but for now they are gard coded.
  7.  
  8.  
  9. // WWW variables that will remain.. Don't replace ...
  10.  
  11. #define MAX_CLIENTS     10    // Maximun number of connections to allow
  12. #define SEND_BUFFER    300    // How many characters to send at a time ..
  13. // State of the sockets below ....
  14. #define SOCK_FREE        4    // The socket is not being used .
  15. #define WAITING          5    // Waiting for the socket to send information
  16. #define SENDING          6    // Sending data to the other server 
  17. #define SOCK_FULL        7    // All sockets aree in use.  Send can msg.
  18.  
  19. #define CLIENT_MSG    WM_USER+1     // The clients is crying ..
  20. #define INCOMING_MSG  WM_USER+2     // The master has closed, or a connections has comed ..
  21.  
  22.  
  23. #define MAX_IN_BUF   100      // how many chars to receive from client .....
  24. #define SEND_BUF_LEN 200      // How many chars to send at a time ....
  25.  
  26. struct WWWSockDef {
  27.     short    State;             // Status of the Socket
  28.     SOCKET   CliSock;
  29.     CString  InBuf;
  30.     CFile    SendFile;
  31.     char     SendBuf[SEND_BUF_LEN];
  32.     int      HowManyInSendBuf;  
  33.     int      OffsetToSend; 
  34.     CTime    LastTime; 
  35.     char     CliIp[30];          // IP Of client.
  36. }; 
  37.     
  38.  
  39. // Misc stuff ..........
  40. #define TIME_TO_CHECK     (360*60)       // Milliseconds to check for inactive connections
  41. #define IdEv               20           // ID Event for Timer.
  42.  
  43. #define INACTIVE          2  // No response in over 3 minutes should be killed.
  44.  
  45.     
  46. //////////////////////////////////////////////////////////////////////
  47. class CSerwebView : public CScrollView
  48. {
  49. protected: // create from serialization only
  50.     CSerwebView();
  51.     DECLARE_DYNCREATE(CSerwebView)
  52.     
  53.     WWWSockDef WWWConv[MAX_CLIENTS+1];    // All conversations going on ....
  54.     SOCKET     WWWServer;               // The popetier - controls all connections
  55.     SOCKET     cli_sock;
  56.     
  57.     struct sockaddr_in srv_addr, cli_addr;
  58.     LPSERVENT srv_info;
  59.     LPHOSTENT host_info;
  60.  
  61.     char buf[200];                      // All purpose buffer.  Usually for error messages.
  62.     
  63.     int WWWPort;             // Port to listen on
  64.     int HowManyClients;      // similar to app one, but for ease of use, lets redefine it and re get it....
  65.  
  66.     CString SendDir;             // From where do we send data ?                
  67.     CString FileNotExistMsg;     // File to send if we can't file a file being requested. 
  68.     CString ClosedServerMsg;     // File to send if server is closed.
  69.     CString PeriodAllowedMsg;    // File to sedn if user send for a file with ..
  70.     
  71. // Attributes
  72. public:
  73.     CSerwebDoc* GetDocument();
  74.  
  75.  
  76. // Operations
  77. public:
  78.     void OnInitialUpdate();
  79.     virtual void OnUpdate(CView* pSender, LPARAM lHint = 0L, CObject* pHint = NULL);
  80.     virtual void PrintSt(CString StToPrint);      
  81.     virtual void PrintSt(char* AString);      
  82.     virtual void PrintChar(char nChar, char OutputIt = 'n');          // Print just one char ....
  83.     virtual void ProcessRequest(int SockNumber);      
  84.     virtual void ProcessRead(int SockNumber);      
  85.     virtual void SendBlockOfData(int SockNumber);      
  86.     virtual CString GetFirstString(CString TheString, int WrdToGet);      
  87.     virtual void KillConn(int SockNumber);
  88.  
  89. // Implementation
  90. public:
  91.     virtual ~CSerwebView();
  92.     virtual void OnDraw(CDC* pDC);  // overridden to draw this view
  93. #ifdef _DEBUG
  94.     virtual void AssertValid() const;
  95.     virtual void Dump(CDumpContext& dc) const;
  96. #endif
  97.  
  98.  
  99. // Generated message map functions
  100. protected:
  101.     //{{AFX_MSG(CSerwebView)
  102.     afx_msg LRESULT OnWWWClientMsg(WPARAM wParam, LPARAM lParam);
  103.     afx_msg LRESULT OnWWWServerMsg(WPARAM wParam, LPARAM lParam);
  104.     afx_msg void OnPeriodOk();
  105.     afx_msg void OnServerInact();
  106.     afx_msg void OnUpdateStat();
  107.     afx_msg void OnTimer(UINT nIDEvent);
  108.     //}}AFX_MSG
  109.     DECLARE_MESSAGE_MAP()
  110. };
  111.  
  112. #ifndef _DEBUG    // debug version in serwevw.cpp
  113. inline CSerwebDoc* CSerwebView::GetDocument()
  114.    { return (CSerwebDoc*) m_pDocument; }
  115. #endif
  116.  
  117. /////////////////////////////////////////////////////////////////////////////
  118.